package thread;

//一个对象执行不同方法，互斥的现象
public class SyncDemo4 {
    public static void main(String[] args) {
       Foo foo1=new Foo();
       Foo foo2=new Foo();
       Thread t1=new Thread(){
           @Override
           public void run() {
               foo1.funA();
           }
       };
        Thread t2=new Thread(){
            @Override
            public void run() {
                foo1.funB();
            }
        };
        t1.start();
        t2.start();
    }
}
class Foo{
    synchronized void funA(){
        try {
            Thread t=Thread.currentThread();
            System.out.println(t.getName()+":执行A方法");
            Thread.sleep(5000);
            System.out.println(t.getName()+":完毕");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
     synchronized void funB(){
        try {
            Thread t=Thread.currentThread();
            System.out.println(t.getName()+":执行B方法");
            Thread.sleep(5000);
            System.out.println(t.getName()+":完毕");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}